package gsql

import "framework/gsql/clause"

type SqlBuilder struct {
	table   string
	columns clause.Column
	wheres  []clause.Where
}

func NewQuery() *SqlBuilder {
	v := &SqlBuilder{}

	return v
}

func (qb *SqlBuilder) Table(name string) *SqlBuilder {
	qb.table = name
	return qb
}

func (qb *SqlBuilder) Select(columns ...string) *SqlBuilder {
	qb.columns = clause.Column{
		Cols: columns,
	}

	return qb
}

// a.where("a", '=', 12)
// a.orWhere(func() {
// 	x.where("ad", "=", 21)
// 	x.where("b", "=", 17)
// })

// where a=12 and b=2
func (qb *SqlBuilder) Where(column string, operator string, value any) *SqlBuilder {

	// expr := &clause.Expr{}

	// qb.wheres.Conditions = append(qb.wheres.Conditions, &clause.Expr{
	// 	Column:   column,
	// 	Operator: clause.OPERATOR_EQ,
	// 	Value:    value,
	// })

	// qb.wheres.conditions = append(qb.wheres.conditions, whereCondition{
	// 	column:   column,
	// 	operator: operator,
	// 	value:    value,
	// 	boolean:  "and",
	// })
	return qb
}

func (qb *SqlBuilder) ToSql() string {

	s := &clause.Builder{}

	qb.columns.BuilderSql(s)
	// qb.wheres.BuilderSql(s)

	return "SELECT " + s.GetSQL()
}
